package com.cdu.guoxinan.www.smartcom.service.impl;

import com.cdu.guoxinan.www.smartcom.domian.dto.QueryRepairDTO;
import com.cdu.guoxinan.www.smartcom.domian.dto.QueryRepairManDTO;
import com.cdu.guoxinan.www.smartcom.domian.dto.RepairDTO;
import com.cdu.guoxinan.www.smartcom.domian.pojo.Repair;
import com.cdu.guoxinan.www.smartcom.domian.vo.RepairVO;
import com.cdu.guoxinan.www.smartcom.mapper.RepairManMapper;
import com.cdu.guoxinan.www.smartcom.mapper.RepairMapper;
import com.cdu.guoxinan.www.smartcom.service.RepairService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;

@Slf4j
@Service
public class RepairServiceImpl implements RepairService {

    @Resource
    private RepairMapper repairMapper;

    @Resource
    private RepairManMapper repairManMapper;


    @Override
    public PageInfo<RepairVO> getAllRepairs(QueryRepairDTO queryRepairDTO) {
        PageHelper.startPage(queryRepairDTO.getPage(), queryRepairDTO.getLimit());
        List<RepairVO> repairs = repairMapper.getAllRepairs(queryRepairDTO);
        return new PageInfo<>(repairs);
    }

    @Override
    public int addRepair(RepairDTO repairDTO) {


        return repairMapper.addRepair(repairDTO);

    }

    @Override
    public int updateRepair(Repair repair) {

        if ( repair.getStatus() != 2 && repair.getCompletedAt() != null){

            System.out.println( "还未干完");
            return -1; // 跟新失败
        }

        return repairMapper.updateRepair(repair);
    }

    @Override
    public int deleteRepair(Long recordId) {
        return repairMapper.deleteRepair(recordId);
    }

    @Override
    public int deleteBatch(Integer[] ids) {

        return repairMapper.deletePatch(ids);
    }
}
